package com.four.marketing.controller;


import com.four.marketing.entity.Seckill;
import com.four.marketing.feign.ShopFeginService;
import com.four.marketing.service.SeckillService;
import com.guli.common.utils.R;
import com.guli.common.vo.ManageVo;
import com.guli.common.vo.ParameterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 侯新伟
 * @since 2021-12-14
 */
@RestController
@RequestMapping("mark/seckill")
public class SeckillController {

    @Autowired
    private ShopFeginService shopFeginService;

    @Autowired
    private SeckillService seckillService;

    /**
     * 查询所有商品
     * @return
     */
    @GetMapping("getManageAll")
    public R getManageAll(){
        List<ManageVo> manageVoList=shopFeginService.findAllManage();
        return R.ok().put("manageVoList",manageVoList);
    }

    /**
     * 根据商品id查询商品信息
     * @param manId
     * @return
     */
    @GetMapping("/getManageById/{manId}")
    public R getManageById(@PathVariable("manId")Integer manId){
        ManageVo manageVo=shopFeginService.getManageById(manId);
        return R.ok().put("manageVo",manageVo);
    }

    /**
     * 根据商品id查询商品属性
     * @param manId
     * @return
     */
    @GetMapping("/getParmeterById/{manId}")
    public R getParmeterById(@PathVariable("manId")Integer manId){
        List<ParameterVo> parameterVoList=shopFeginService.findParameterById(manId);
        return R.ok().put("parameterVoList",parameterVoList);
    }

    /**
     * 添加秒杀商品
     * @param seckill
     * @return
     */
    @PostMapping("/addSeckill/{conId}")
    public R addSeckill(@RequestBody Seckill seckill,@PathVariable("conId}")Integer conId){
        seckill.setConId(conId);
        seckillService.addSeckill(seckill);
        return R.ok();
    }

    /**
     * 根据id获取秒杀信息
     * @param seId
     * @return
     */

    @GetMapping("/findSeckillId/{seId}")
    public R findSeckillId(@PathVariable("seId")Integer seId){
        Seckill seckill = seckillService.findSeckillId(seId);
        return R.ok().put("seckill",seckill);
    }

    /**
     * 修改
     * @param seckill
     * @return
     */

    @PutMapping("/updateSeckill")
    public R updateSeckill(@RequestBody Seckill seckill){
        seckillService.updateSeckill(seckill);
        return R.ok();
    }

    @DeleteMapping("deleteById/{id}")
    public R deleteById(@PathVariable("id")Integer id){
        seckillService.deleteById(id);
        return R.ok();
    }



}
